﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using UnityEngine.UI;

public class RenWuPanel : MonoBehaviour
{

    public Button Button1, Button2, Button3, Button4;
    public GameObject FinishOrNot1, FinishOrNot2, FinishOrNot3, FinishOrNot4;
    public bool Finish1, Finish2, Finish3, Finish4;
    public Image JinDu1, JinDu2, JinDu3, JinDu4;
    public Text RenWuText1, RenWuText2, RenWuText3, RenWuText4;
    public Text Button1Text, Button2Text, Button3Text, Button4Text;
    public int JiangLiNum;
    
    void Awake()
    {

        GetAllData();
        JiangLiJinEr();
        Button1.onClick.AddListener(OnClickButton1);
        Button2.onClick.AddListener(OnClickButton2);
        Button3.onClick.AddListener(OnClickButton3);
        Button4.onClick.AddListener(OnClickButton4);
        if (JinDu1.fillAmount == 1)
        {
            Finish1 = true;

        }
        if (JinDu2.fillAmount == 1)
        {
            Finish2 = true;

        }
        if (JinDu3.fillAmount == 1)
        {
            Finish3 = true;

        }
        if (JinDu4.fillAmount == 1)
        {
            Finish4 = true;

        }
        FinishOrNotFirst();
        FinishOrNotSecond();
        FinishOrNotThird();
        FinishOrNotFourth();
       

    }

    private void Update()
    {
        JustOne();
    }
    /// <summary>
    /// /读取数据
    /// </summary>
    public void GetAllData()
    {
        //消灭次数
        JinDu1.fillAmount = (float)DataManager.Instance.XiaoMieNum / 100;
        Debug.Log("DataManager.Instance.GetRenWuShuJu().XiaoMieNum==" + DataManager.Instance.XiaoMieNum);
        RenWuText1.text = DataManager.Instance.XiaoMieNum.ToString() + "/100";
        //玩游戏次数
        JinDu2.fillAmount = (float)DataManager.Instance.PlayTimes / 50;
        Debug.Log("DataManager.Instance.GetRenWuShuJu().PlayTimes===" + DataManager.Instance.PlayTimes);
        RenWuText2.text = DataManager.Instance.PlayTimes.ToString() + "/50";
        //升级攻击次数
        JinDu3.fillAmount = (float)DataManager.Instance.AddHurt / 5;
        RenWuText3.text = DataManager.Instance.AddHurt.ToString() + "/100";
        //消灭Boss次数
        JinDu4.fillAmount = (float)DataManager.Instance.XiaoMieBossNum / 1;
        RenWuText4.text = DataManager.Instance.XiaoMieBossNum.ToString() + "/1";




    }
    /// <summary>
    /// 奖励金额显示
    /// </summary>
    public void JiangLiJinEr()
    {
        Debug.Log("DataManager.Instance.GuDing==" + DataManager.Instance.GuDing);
       
            JiangLiNum = DataManager.Instance.Lv * 100;
         
            if (JiangLiNum >= 1000)
            {
                Button1Text.text = ((JiangLiNum / 1000) + (float)(JiangLiNum % 1000) / 1000).ToString() + "k";
                Button2Text.text = ((JiangLiNum / 1000) + (float)(JiangLiNum % 1000) / 1000).ToString() + "k";
                Button3Text.text = ((JiangLiNum / 1000) + (float)(JiangLiNum % 1000) / 1000).ToString() + "k";
                Button4Text.text = ((JiangLiNum / 1000) + (float)(JiangLiNum % 1000) / 1000).ToString() + "k";
            }
            else
            {
                Button1Text.text = JiangLiNum.ToString();
                Button2Text.text = JiangLiNum.ToString();
                Button3Text.text = JiangLiNum.ToString();
                Button4Text.text = JiangLiNum.ToString();
            }
           
        
    }
    /// <summary>
    /// 第一个任务是否完成
    /// </summary>
    public void FinishOrNotFirst()
    {
        if (Finish1)
        {
            FinishOrNot1.transform.GetChild(0).gameObject.SetActive(false);
            FinishOrNot1.transform.GetChild(1).gameObject.SetActive(true);
            Button1.interactable = true;
        }
        else
        {
            FinishOrNot1.transform.GetChild(0).gameObject.SetActive(true);
            FinishOrNot1.transform.GetChild(1).gameObject.SetActive(false);
            Button1.interactable = false;
        }

    }
    /// <summary>
    /// /只能完成一次
    /// </summary>
    public void JustOne()
    {
        if (DataManager.Instance.FinishFirst == 1)
        {
            Button1.interactable = false
;
        }
        if (DataManager.Instance.FinishSecond == 1)
        {
            Button2.interactable = false
;
        }
        if (DataManager.Instance.FinishThird == 1)
        {
            Button3.interactable = false
;
        }
        if (DataManager.Instance.FinishFourth == 1)
        {
            Button4.interactable = false
;
        }
    }
    /// <summary>
    /// 第二个任务是否完成
    /// </summary>
    public void FinishOrNotSecond()
    {
        if (Finish2)
        {
            FinishOrNot2.transform.GetChild(0).gameObject.SetActive(false);
            FinishOrNot2.transform.GetChild(1).gameObject.SetActive(true);
            Button2.interactable = true;
        }
        else
        {
            FinishOrNot2.transform.GetChild(0).gameObject.SetActive(true);
            FinishOrNot2.transform.GetChild(1).gameObject.SetActive(false);
            Button2.interactable = false;
        }

    }
    /// <summary>
    /// 第三个任务是否完成
    /// </summary>
    public void FinishOrNotThird()
    {
        if (Finish3)
        {
            FinishOrNot3.transform.GetChild(0).gameObject.SetActive(false);
            FinishOrNot3.transform.GetChild(1).gameObject.SetActive(true);
            Button3.interactable = true;
        }
        else
        {
            FinishOrNot3.transform.GetChild(0).gameObject.SetActive(true);
            FinishOrNot3.transform.GetChild(1).gameObject.SetActive(false);
            Button3.interactable = false;
        }

    }
    /// <summary>
    /// 第四个任务是否完成
    /// </summary>
    public void FinishOrNotFourth()
    {
        if (Finish4)
        {
            FinishOrNot4.transform.GetChild(0).gameObject.SetActive(false);
            FinishOrNot4.transform.GetChild(1).gameObject.SetActive(true);
            Button4.interactable = true;
        }
        else
        {
            FinishOrNot4.transform.GetChild(0).gameObject.SetActive(true);
            FinishOrNot4.transform.GetChild(1).gameObject.SetActive(false);
            Button4.interactable = false;
        }

    }

    /// <summary>
    /// 第一个任务按钮
    /// </summary>
    public void OnClickButton1()
    {
        ShortVoice.instance.PlayVoice("AnNiu");
        DataManager.Instance.FinishFirst += 1;
        DataManager.Instance.Gold += DataManager.Instance.Lv * 100;
        DataManager.Instance.Save();//存
        GoldAndLv.instance.GengXin();//更新金币显示

    }
    /// <summary>
    /// /第二个任务按钮
    /// </summary>
    public void OnClickButton2()
    {
        ShortVoice.instance.PlayVoice("AnNiu");
        DataManager.Instance.FinishSecond += 1;
        DataManager.Instance.Gold += DataManager.Instance.Lv * 100;
        DataManager.Instance.Save();//存
        GoldAndLv.instance.GengXin();

    }
    /// <summary>
    /// /第三个任务按钮
    /// </summary>
    public void OnClickButton3()
    {

        ShortVoice.instance.PlayVoice("AnNiu");
        DataManager.Instance.FinishThird += 1;
        DataManager.Instance.Gold += DataManager.Instance.Lv * 100;
        DataManager.Instance.Save();//存
        GoldAndLv.instance.GengXin();

    }
    /// <summary>
    /// /第四个任务按钮
    /// </summary>
    public void OnClickButton4()
    {

        ShortVoice.instance.PlayVoice("AnNiu");
        DataManager.Instance.FinishFourth += 1;
        DataManager.Instance.Gold += DataManager.Instance.Lv * 100;
        DataManager.Instance.Save();//存
        GoldAndLv.instance.GengXin();

    }
}
